package com.my.spring.demo.controllers;

import com.my.spring.demo.services.UserService;
import com.my.spring.framework.annotation.MyAutowired;
import com.my.spring.framework.annotation.MyController;
import com.my.spring.framework.annotation.MyRequestMapping;
import com.my.spring.framework.annotation.MyRequestParam;
import com.my.spring.framework.webmvc.servlet.MyModelAndView;

import java.util.HashMap;
import java.util.Map;

@MyController
@MyRequestMapping("/demo")
public class Welcome {
    @MyAutowired
    UserService userService;

    @MyRequestMapping("/str2template")
    public String testStr2template() {
        return "template";
    }

    @MyRequestMapping("/mv")
    public MyModelAndView testMv(@MyRequestParam("name") String name, @MyRequestParam("age") int age) {
        System.out.println("name: " + name);
        System.out.println("age: " + age);
        userService.sayHello(name);
        Map<String, Object> model = new HashMap<>();
        model.put("name", name);
        model.put("age", age);
        return new MyModelAndView("template", model);
    }
}
